package com.sxyc.weixin.controller;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.kit.PropKit;
import com.jfinal.weixin.sdk.api.ApiConfig;
import com.jfinal.weixin.sdk.api.ApiResult;
import com.jfinal.weixin.sdk.api.CustomServiceApi;
import com.jfinal.weixin.sdk.jfinal.MsgControllerAdapter;
import com.jfinal.weixin.sdk.msg.in.InImageMsg;
import com.jfinal.weixin.sdk.msg.in.InLinkMsg;
import com.jfinal.weixin.sdk.msg.in.InLocationMsg;
import com.jfinal.weixin.sdk.msg.in.InShortVideoMsg;
import com.jfinal.weixin.sdk.msg.in.InTextMsg;
import com.jfinal.weixin.sdk.msg.in.InVideoMsg;
import com.jfinal.weixin.sdk.msg.in.InVoiceMsg;
import com.jfinal.weixin.sdk.msg.in.event.InCustomEvent;
import com.jfinal.weixin.sdk.msg.in.event.InFollowEvent;
import com.jfinal.weixin.sdk.msg.in.event.InLocationEvent;
import com.jfinal.weixin.sdk.msg.in.event.InMassEvent;
import com.jfinal.weixin.sdk.msg.in.event.InMenuEvent;
import com.jfinal.weixin.sdk.msg.in.event.InQrCodeEvent;
import com.jfinal.weixin.sdk.msg.in.event.InTemplateMsgEvent;
import com.jfinal.weixin.sdk.msg.in.speech_recognition.InSpeechRecognitionResults;
import com.jfinal.weixin.sdk.msg.out.News;
import com.jfinal.weixin.sdk.msg.out.OutCustomMsg;
import com.jfinal.weixin.sdk.msg.out.OutNewsMsg;
import com.jfinal.weixin.sdk.msg.out.OutTextMsg;
import com.jfinal.weixin.sdk.msg.out.OutVoiceMsg;
import com.jfinal.weixin.sdk.utils.HttpUtils;
import com.jfinal.weixin.sdk.api.CustomServiceApi.Articles;
import com.sxyc.tintin.controller.CommonController;
import com.sxyc.tintin.model.DeviceBinding;
import com.sxyc.tintin.model.Person;

/**
 * 微信消息接收类
 * 
 * @author WangQian 将此 DemoController 在YourJFinalConfig 中注册路由， 并设置好weixin开发者中心的
 *         URL 与 token ，使 URL 指向该 DemoController 继承自父类 WeixinController 的 index
 *         方法即可直接运行看效果，在此基础之上修改相关的方法即可进行实际项目开发
 */
public class WeixinMsgController extends MsgControllerAdapter {

	// 使用jFinal 日志
	private static com.jfinal.log.Log logger = com.jfinal.log.Log.getLog(WeixinMsgController.class);

	private static final String helpStr = "\t 欢迎使用，祝您愉快！";
	
	private static final String webServiceURL = "http://apis.map.qq.com/ws/place/v1/search?";
	
	private static final String address="http://apis.map.qq.com/ws/geocoder/v1/?address=";
	/**
	 * 如果要支持多公众账号，只需要在此返回各个公众号对应的 ApiConfig 对象即可 可以通过在请求 url 中挂参数来动态从数据库中获取
	 * ApiConfig 属性值
	 */
	public ApiConfig getApiConfig() {
		ApiConfig ac = new ApiConfig();

		// 配置微信 API 相关常量
		ac.setToken(PropKit.get("token"));
		ac.setAppId(PropKit.get("appId"));
		ac.setAppSecret(PropKit.get("appSecret"));

		/**
		 * 是否对消息进行加密，对应于微信平台的消息加解密方式： 1：true进行加密且必须配置 encodingAesKey
		 * 2：false采用明文模式，同时也支持混合模式
		 */
		ac.setEncryptMessage(PropKit.getBoolean("encryptMessage", false));
		ac.setEncodingAesKey(PropKit.get("encodingAesKey", ""));
		return ac;
	}

	/**
	 * 接收消息-1.文本消息
	 */
	@Override
	protected void processInTextMsg(InTextMsg inTextMsg) {
		String openId = inTextMsg.getFromUserName();
		DeviceBinding user = DeviceBinding.dao.getWxUserByOpenId(openId);
		if(user.get("DeviceId")==null){
			logger.info("【该用户未绑定终端，不能执行导航操作！】");
		}else{
			String msgContent = inTextMsg.getContent().trim();
			logger.info("【接收文本消息事件】openId = " + openId + " ; msgContent = " + msgContent);

			OutNewsMsg outNews = new OutNewsMsg(inTextMsg);
			List<News> articles = new ArrayList<News>();
			String message = "";
			if (msgContent != null && msgContent.contains("市")) {
				String url=address+msgContent+"&key="+PropKit.get("qqMap_webService");
					String json=HttpUtils.get(url);
					JSONObject res = JSONObject.parseObject(json);
					Object object=res.get("result");
					JSONObject lists = JSONObject.parseObject(JSONObject.parseObject(object.toString()).get("location").toString());
					double lng= Double.parseDouble(lists.get("lng").toString());
					double lat=Double.parseDouble(lists.get("lat").toString());
					System.out.println(lng+"------------------"+lat);
					String destinarion=webServiceURL+"keyword="+msgContent+"&boundary=nearby("+lat+","+lng+",1000)&key="+PropKit.get("qqMap_webService");
					json=HttpUtils.get(destinarion);
					JSONObject ress = JSONObject.parseObject(json);
					JSONArray openIdList = ress.getJSONArray("data");
					int i=0;
					for (Object object2 : openIdList) {
						JSONObject list = JSONObject.parseObject(object2.toString());
						String address=list.get("address").toString();
						JSONObject lists2 = JSONObject.parseObject(JSONObject.parseObject(list.toString()).get("location").toString());
						double lng2= Double.parseDouble(lists2.get("lng").toString());
						double lat2=Double.parseDouble(lists2.get("lat").toString());
						System.out.println(address+"---"+lng2+"------------------"+lat2);
						i=i+1;
						if(i==1){
							News article = new News();
							article.setTitle(list.get("address").toString());//标题
							article.setDescription("");//图文描述
							article.setPicUrl(PropKit.get("root_url")+"/wx/images/map.png");//图片url
							article.setUrl(PropKit.get("root_url")+"/wx/jsp/view_destination.jsp?lng="+lng2+"&lat="+lat2+"&address="+address+"&openId="+openId);//跳转路径
							articles.add(article);
						}else if(i==9){
							break;
						}else if(i==8){
							News article = new News();
							article.setTitle("提示：默认是西安市搜索，外地搜索请加上城市名,比如说某某市/区人民路。\n 客服电话：029-88447656");//标题
							article.setDescription("");//图文描述2
							articles.add(article);
						}else{
							News article = new News();
							article.setTitle(list.get("address").toString());//标题
							article.setDescription("");//图文描述
							article.setUrl(PropKit.get("root_url")+"/wx/jsp/view_destination.jsp?lng="+lng2+"&lat="+lat2+"&address="+address+"&openId="+openId);//跳转路径
							articles.add(article);
						}

					}
					outNews.setArticles(articles);
					render(outNews);
		}else{
			String privince="西安市";
			String url=address+privince+msgContent+"&key="+PropKit.get("qqMap_webService");
				String json=HttpUtils.get(url);
				JSONObject res = JSONObject.parseObject(json);
				Object object=res.get("result");
				JSONObject lists = JSONObject.parseObject(JSONObject.parseObject(object.toString()).get("location").toString());
				double lng= Double.parseDouble(lists.get("lng").toString());
				double lat=Double.parseDouble(lists.get("lat").toString());
				System.out.println(lng+"------------------"+lat);
				String destinarion=webServiceURL+"keyword="+msgContent+"&boundary=nearby("+lat+","+lng+",1000)&key="+PropKit.get("qqMap_webService");
				json=HttpUtils.get(destinarion);
				JSONObject ress = JSONObject.parseObject(json);
				JSONArray openIdList = ress.getJSONArray("data");
				int i=0;
				for (Object object2 : openIdList) {
					JSONObject list = JSONObject.parseObject(object2.toString());
					String address=list.get("address").toString();
					JSONObject lists2 = JSONObject.parseObject(JSONObject.parseObject(list.toString()).get("location").toString());
					double lng2= Double.parseDouble(lists2.get("lng").toString());
					double lat2=Double.parseDouble(lists2.get("lat").toString());
					System.out.println(address+"---"+lng2+"------------------"+lat2);
					i=i+1;
					if(i==1){
						News article = new News();
						article.setTitle(list.get("address").toString());//标题
						article.setDescription("");//图文描述
						article.setPicUrl(PropKit.get("root_url")+"/wx/images/map.png");//图片url
						article.setUrl(PropKit.get("root_url")+"/wx/jsp/view_destination.jsp?lng="+lng2+"&lat="+lat2+"&address="+address+"&openId="+openId);//跳转路径
						articles.add(article);
					}else if(i==9){
						break;
					}else if(i==8){
						News article = new News();
						article.setTitle("提示：默认是西安市搜索，外地搜索请加上城市名,比如说某某市/区人民路。\n 客服电话：029-88447656");//标题
						article.setDescription("");//图文描述2
						articles.add(article);
					}else{
						News article = new News();
						article.setTitle(list.get("address").toString());//标题
						article.setDescription("");//图文描述
						article.setUrl(PropKit.get("root_url")+"/wx/jsp/view_destination.jsp?lng="+lng2+"&lat="+lat2+"&address="+address+"&openId="+openId);//跳转路径
						articles.add(article);
					}

				}
				outNews.setArticles(articles);
				render(outNews);
		}
		
	}
	}

	/**
	 * 接收消息-2.图片消息
	 */
	@Override
	protected void processInImageMsg(InImageMsg inImageMsg) {
		String picUrl = inImageMsg.getPicUrl();
		String respContent = picUrl;
		renderOutTextMsg(respContent);
	}

	/**
	 * 接收消息-3.语音消息
	 */
	@Override
	protected void processInVoiceMsg(InVoiceMsg inVoiceMsg) {
		OutVoiceMsg outMsg = new OutVoiceMsg(inVoiceMsg);
		System.out.println("nihao ");
		// 将刚发过来的语音再发回去
		outMsg.setMediaId(inVoiceMsg.getMediaId());
		render(outMsg);
	}

	/**
	 * 接收消息-4.视频消息
	 */
	@Override
	protected void processInVideoMsg(InVideoMsg inVideoMsg) {
		/*
		 * 腾讯 api 有 bug，无法回复视频消息，暂时回复文本消息代码测试 OutVideoMsg outMsg = new
		 * OutVideoMsg(inVideoMsg); outMsg.setTitle("OutVideoMsg 发送");
		 * outMsg.setDescription("刚刚发来的视频再发回去"); // 将刚发过来的视频再发回去，经测试证明是腾讯官方的 api
		 * 有 bug，待 api bug 却除后再试 outMsg.setMediaId(inVideoMsg.getMediaId());
		 * render(outMsg);
		 */
		OutTextMsg outMsg = new OutTextMsg(inVideoMsg);
		outMsg.setContent("\t视频消息已成功接收，该视频的 mediaId 为: " + inVideoMsg.getMediaId());
		render(outMsg);
	}

	/**
	 * 接收消息-5.小视频消息
	 */
	@Override
	protected void processInShortVideoMsg(InShortVideoMsg inShortVideoMsg) {
		OutTextMsg outMsg = new OutTextMsg(inShortVideoMsg);
		outMsg.setContent("\t视频消息已成功接收，该视频的 mediaId 为: " + inShortVideoMsg.getMediaId());
		render(outMsg);
	}

	/**
	 * 接收消息-6.地理位置消息
	 */
	@Override
	protected void processInLocationMsg(InLocationMsg inLocationMsg) {
		OutTextMsg outMsg = new OutTextMsg(inLocationMsg);
		outMsg.setContent("已收到地理位置消息:" + "\nlocation_X = " + inLocationMsg.getLocation_X() + "\nlocation_Y = "
				+ inLocationMsg.getLocation_Y() + "\nscale = " + inLocationMsg.getScale() + "\nlabel = "
				+ inLocationMsg.getLabel());
		render(outMsg);
	}

	/**
	 * 接收消息-7.链接消息
	 */
	@Override
	protected void processInLinkMsg(InLinkMsg inLinkMsg) {
		// 转发给多客服PC客户端
		OutCustomMsg outCustomMsg = new OutCustomMsg(inLinkMsg);
		render(outCustomMsg);
	}

	/**
	 * 处理事件-1.关注/取消关注事件
	 */
	@Override
	protected void processInFollowEvent(InFollowEvent inFollowEvent) {
		if (InFollowEvent.EVENT_INFOLLOW_SUBSCRIBE.equals(inFollowEvent.getEvent())) {
			logger.info("关注：" + inFollowEvent.getFromUserName());
			OutTextMsg outMsg = new OutTextMsg(inFollowEvent);
			outMsg.setContent(helpStr);
			render(outMsg);
		}
		// 如果为取消关注事件，将无法接收到传回的信息
		if (InFollowEvent.EVENT_INFOLLOW_UNSUBSCRIBE.equals(inFollowEvent.getEvent())) {
			logger.info("取消关注：" + inFollowEvent.getFromUserName());
			CommonController.unBinding(inFollowEvent.getFromUserName());
		}
	}

	/**
	 * 处理事件-2.扫描带参数二维码事件
	 */
	@Override
	protected void processInQrCodeEvent(InQrCodeEvent inQrCodeEvent) {
		String openId = inQrCodeEvent.getFromUserName();
		/*
		 * 如果未关注：sceneId = qrscene_sceneId 需要去掉前缀qrscene_ 如果已关注：sceneId 可以直接使用
		 */
		String sceneId = inQrCodeEvent.getEventKey().replaceAll("qrscene_", "");

		logger.info("【触发扫码事件】openId = " + openId + " ; sceneId = " + sceneId);

		if (InQrCodeEvent.EVENT_INQRCODE_SUBSCRIBE.equals(inQrCodeEvent.getEvent())) {
			logger.info("状态：扫码未关注");
		}
		if (InQrCodeEvent.EVENT_INQRCODE_SCAN.equals(inQrCodeEvent.getEvent())) {
			logger.info("状态：扫码已关注");
		}

		int code = CommonController.binding(openId, sceneId);
		System.out.println("code---->"+code);
		if(code==0){
			renderOutTextMsg("该设备已经绑定其他微信，暂时无法绑定！");
		}else if(code==1){
			OutNewsMsg outNews = new OutNewsMsg(inQrCodeEvent);
			List<News> articles = new ArrayList<News>();
			News article1 = new News();
			article1.setTitle("厉害了word哥，17步带你玩转叮当");//标题
			article1.setDescription("");//图文描述
			article1.setPicUrl(PropKit.get("root_url")+"/wx/images/ddang.png");//图片url
			article1.setUrl(PropKit.get("root_url")+"/wx/html/instructions.html");//跳转路径
			articles.add(article1);
			//推送一条消息
			News article2 = new News();
			article2.setTitle("叮当30问");//标题
			article2.setDescription("");//图文描述
			article2.setPicUrl(PropKit.get("root_url")+"/wx/images/30wen.jpg");//图片url
			article2.setUrl(PropKit.get("root_url")+"/wx/html/question.html");//跳转路径
			articles.add(article2);
			//感谢您使用".AmiConfig::WXNAME."微信服务! 您已成功绑定设备".$deviceId.",感谢您的使用
			News article4 = new News();
			article4.setTitle("感谢您使用叮当微信服务!");//标题
			article4.setDescription("");//图文描述
			article4.setPicUrl(PropKit.get("root_url")+"/wx/images/ganxie.jpg");//图片url
			articles.add(article4);
			outNews.setArticles(articles);
			render(outNews);
			//renderJson(CustomServiceApi.sendNews(openId, articles));
		}else if(code==2 || code==3){
			renderOutTextMsg("该设备绑定微信失败，请重新绑定！");
		}
	}

	/**
	 * 处理事件-3.上报地理位置事件
	 */
	@Override
	protected void processInLocationEvent(InLocationEvent inLocationEvent) {
		logger.info("发送地理位置事件：" + inLocationEvent.getFromUserName());
		OutTextMsg outMsg = new OutTextMsg(inLocationEvent);
		outMsg.setContent("地理位置是：" + inLocationEvent.getLatitude());
		renderText("");
	}

	/**
	 * 处理事件-4.自定义菜单事件
	 */
	@Override
	protected void processInMenuEvent(InMenuEvent inMenuEvent) {
		logger.info("菜单事件：" + inMenuEvent.getFromUserName());
		OutTextMsg outMsg = new OutTextMsg(inMenuEvent);
		String str = "";
		if("CLICK".equals(inMenuEvent.getEvent())){
			// 根据openId获取用户信息
			Person person = Person.dao.getUserByOpenId(inMenuEvent.getFromUserName());
//			if (person == null) {
//				// 跳转到注册页面
//				System.out.println("用户未注册");
//				OutNewsMsg outNews = new OutNewsMsg(inMenuEvent);
//				render(outNews);
//			}else{
				if("hello".equals(inMenuEvent.getEventKey())){
					str = "你好，欢迎关注叮当物流公众号\n绑定设备将获得更好体验哦！";
				}else if("photo".equals(inMenuEvent.getEventKey())){
					str = CommonController.getPhoto(inMenuEvent.getFromUserName());
				}else if("video".equals(inMenuEvent.getEventKey())){
					str = CommonController.getVideo(inMenuEvent.getFromUserName());
				}else if("instruction".equals(inMenuEvent.getEventKey())){
					List<News> articles = getNews();
					OutNewsMsg outNews = new OutNewsMsg(inMenuEvent);
					outNews.setArticles(articles);
					render(outNews);
				}else if("advert".equals(inMenuEvent.getEventKey())){
					str = "欢迎拨打 18991915757 了解详细广告投放事宜/::*";
				}else if("new".equals(inMenuEvent.getEventKey())){
					str = "新栏目上线，敬请期待！";
				}
//			}
			if(str!=null && !"".equals(str)){
				outMsg.setContent(str);
				render(outMsg);
			}
		}else{
			renderText("");
		}
	}

	/**
	 * 处理事件-5.点击菜单拉取消息时的事件推送
	 */

	/**
	 * 处理事件-6.点击菜单跳转链接时的事件推送
	 */

	@Override
	protected void processInCustomEvent(InCustomEvent inCustomEvent) {
		logger.info("测试方法：processInCustomEvent()");
		renderNull();
	}

	/**
	 * 模板消息发送通知事件
	 */
	@Override
	protected void processInTemplateMsgEvent(InTemplateMsgEvent inTemplateMsgEvent) {
		logger.info("测试方法：processInTemplateMsgEvent()");
		renderNull();
	}

	/**
	 * 群发消息通知事件
	 */
	@Override
	protected void processInMassEvent(InMassEvent inMassEvent) {
		logger.info("测试方法：processInMassEvent()");
		renderNull();
	}

	/**
	 * 接收语音识别结果事件
	 */
	@Override
	protected void processInSpeechRecognitionResults(InSpeechRecognitionResults inSpeechRecognitionResults) {
		logger.info("语音识别事件：" + inSpeechRecognitionResults.getFromUserName());
		String openId=inSpeechRecognitionResults.getFromUserName();
		OutTextMsg outMsg = new OutTextMsg(inSpeechRecognitionResults);
		outMsg.setContent(inSpeechRecognitionResults.getRecognition());
		String msgContent=outMsg.getContent();
		System.out.println("msgContent"+msgContent);
		DeviceBinding user = DeviceBinding.dao.getWxUserByOpenId(openId);
		if(user.get("DeviceId")==null){
			logger.info("【该用户未绑定终端，不能执行导航操作！】");
		}else{
			logger.info("【接收语音消息事件】openId = " + openId + " ; msgContent = " + msgContent);
			if (msgContent != null && msgContent.contains("市")) {
				String url=address+msgContent+"&key="+PropKit.get("qqMap_webService");
					String json=HttpUtils.get(url);
					JSONObject res = JSONObject.parseObject(json);
					Object object=res.get("result");
					JSONObject lists = JSONObject.parseObject(JSONObject.parseObject(object.toString()).get("location").toString());
					double lng= Double.parseDouble(lists.get("lng").toString());
					double lat=Double.parseDouble(lists.get("lat").toString());
					String destinarion=webServiceURL+"keyword="+msgContent+"&boundary=nearby("+lat+","+lng+",1000)&key="+PropKit.get("qqMap_webService");
					json=HttpUtils.get(destinarion);
					JSONObject ress = JSONObject.parseObject(json);
					JSONArray openIdList = ress.getJSONArray("data");
					List<Articles> articles = new ArrayList<Articles>();
					int i=0;
					for (Object object2 : openIdList) {
						JSONObject list = JSONObject.parseObject(object2.toString());
						String address=list.get("address").toString();
						JSONObject lists2 = JSONObject.parseObject(JSONObject.parseObject(list.toString()).get("location").toString());
						double lng2= Double.parseDouble(lists2.get("lng").toString());
						double lat2=Double.parseDouble(lists2.get("lat").toString());
						i=i+1;
						if(i==1){
							Articles article = new Articles();
							article.setTitle(list.get("address").toString());//标题
							article.setDescription("");//图文描述
							article.setPicurl(PropKit.get("root_url")+"/wx/images/map.png");//图片url
							article.setUrl(PropKit.get("root_url")+"/wx/jsp/view_destination.jsp?lng="+lng2+"&lat="+lat2+"&address="+address+"&openId="+openId);//跳转路径
							articles.add(article);
						}else if(i==9){
							break;
						}else if(i==8){
							Articles article = new Articles();
							article.setTitle("提示：默认是西安市搜索，外地搜索请加上城市名,比如说某某市/区人民路。\n 客服电话：029-88447656");//标题
							article.setDescription("");//图文描述2
							articles.add(article);
						}else{
							Articles article = new Articles();
							article.setTitle(list.get("address").toString());//标题
							article.setDescription("");//图文描述
							article.setUrl(PropKit.get("root_url")+"/wx/jsp/view_destination.jsp?lng="+lng2+"&lat="+lat2+"&address="+address+"&openId="+openId);//跳转路径
							articles.add(article);
						}

					}
					ApiResult result=CustomServiceApi.sendNews(openId, articles);
					System.out.println("result----->"+result);
		}else{
			String privince="西安市";
			String url=address+privince+msgContent+"&key="+PropKit.get("qqMap_webService");
				String json=HttpUtils.get(url);
				JSONObject res = JSONObject.parseObject(json);
				Object object=res.get("result");
				JSONObject lists = JSONObject.parseObject(JSONObject.parseObject(object.toString()).get("location").toString());
				double lng= Double.parseDouble(lists.get("lng").toString());
				double lat=Double.parseDouble(lists.get("lat").toString());
				String destinarion=webServiceURL+"keyword="+msgContent+"&boundary=nearby("+lat+","+lng+",1000)&key="+PropKit.get("qqMap_webService");
				json=HttpUtils.get(destinarion);
				JSONObject ress = JSONObject.parseObject(json);
				JSONArray openIdList = ress.getJSONArray("data");
				List<Articles> articles = new ArrayList<Articles>();
				int i=0;
				for (Object object2 : openIdList) {
					JSONObject list = JSONObject.parseObject(object2.toString());
					String address=list.get("address").toString();
					JSONObject lists2 = JSONObject.parseObject(JSONObject.parseObject(list.toString()).get("location").toString());
					double lng2= Double.parseDouble(lists2.get("lng").toString());
					double lat2=Double.parseDouble(lists2.get("lat").toString());
					i=i+1;
					if(i==1){
						Articles article = new Articles();
						article.setTitle(list.get("address").toString());//标题
						article.setDescription("");//图文描述
						article.setPicurl(PropKit.get("root_url")+"/wx/images/map.png");//图片url
						article.setUrl(PropKit.get("root_url")+"/wx/jsp/view_destination.jsp?lng="+lng2+"&lat="+lat2+"&address="+address+"&openId="+openId);//跳转路径
						articles.add(article);
					}else if(i==9){
						break;
					}else if(i==8){
						Articles article = new Articles();
						article.setTitle("提示：默认是西安市搜索，外地搜索请加上城市名,比如说某某市/区人民路。\n 客服电话：029-88447656");//标题
						article.setDescription("");//图文描述2
						articles.add(article);
					}else{
						Articles article = new Articles();
						article.setTitle(list.get("address").toString());//标题
						article.setDescription("");//图文描述
						article.setUrl(PropKit.get("root_url")+"/wx/jsp/view_destination.jsp?lng="+lng2+"&lat="+lat2+"&address="+address+"&openId="+openId);//跳转路径
						articles.add(article);
					}

				}
				ApiResult result=CustomServiceApi.sendNews(openId, articles);
				System.out.println("result----->"+result);
		}
	}
	}
	
	public List<News> getNews(){
		List<News> articles = new ArrayList<News>();
		News article1 = new News();
		article1.setTitle("厉害了word哥，13步带你玩转叮当");//标题
		article1.setDescription("");//图文描述
		article1.setPicUrl(PropKit.get("root_url")+"/wx/images/ddang.png");//图片url
		article1.setUrl(PropKit.get("root_url")+"/wx/html/instructions.html");//跳转路径
		articles.add(article1);
		//推送一条消息
		News article2 = new News();
		article2.setTitle("叮当30问");//标题
		article2.setDescription("");//图文描述
		article2.setPicUrl(PropKit.get("root_url")+"/wx/images/30wen.jpg");//图片url
		article2.setUrl(PropKit.get("root_url")+"/wx/html/question.html");//跳转路径
		articles.add(article2);
//		//推送一条消息
//		News article3 = new News();
//		article3.setTitle("实景拍摄，易行丁丁一路有你，温馨一路");//标题
//		article3.setDescription("");//图文描述
//		article3.setPicUrl(PropKit.get("root_url")+"/wx/images/jixiangsanbao.jpg");//图片url
//		article3.setUrl("http://v.youku.com/v_show/id_XMTU3NzE2OTQ4MA==.html");//跳转路径
//		articles.add(article3);	
		return articles;
	}
}
